import 'package:fluintl/fluintl.dart';
import 'package:x3_base_core/base_models/base_language_model.dart';

/// 获取多语言
class BaseIntlUtil {

  /// 多语言 私有成员变量
  Map<String, Map<String, Map<String, String>>> _currentLanguages = {
    'en': {'US': {}},
    'zh': {'CN': {}}
  };

  /// 获取多语言
  Map<String, Map<String, Map<String, String>>> get currentLanguages => _currentLanguages;

  /// 设置多语言
  BaseIntlUtil setCurrentLanguages(List<BaseLanguageModel> mLists) {
    this._currentLanguages = _initLanguages(mLists);
    return this;
  }

  /// 初始化多语言
  _initLanguages(List<BaseLanguageModel> mLists) {
    Map<String, Map<String, Map<String, String>>> datas = {
      'en': {'US': {}},
      'zh': {'CN': {}}
    };
    for (var i = 0; i < mLists.length; i++) {
      BaseLanguageModel baseLanguage = mLists[i];
      datas['zh']['CN'][baseLanguage.id] = baseLanguage.zhCh;
      datas['en']['US'][baseLanguage.id] = baseLanguage.enUs;
    }
    return datas;
  }

  /// 根据语言编号获取多语言
  static String getString(context, String key, {String languageCode, String countryCode, List<Object> params}) {
    return IntlUtil.getString(context, key, languageCode: languageCode, countryCode: countryCode, params: params);
  }

}
